package com.charmzenus.it.order.controller;

import com.charmzenus.it.feign.MemberClient;
import com.charmzenus.it.redis.IRedisService;
import feign.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;


@RefreshScope
@RestController
@RequestMapping("/test")
public class TestController {

    @Autowired
    IRedisService iRedisService;

    @Autowired
    MemberClient memberClient;


    @Value("${env}")
    private String env;

    @GetMapping("/test")
    public String test() {
        return "hello = " + env;
    }


    @GetMapping("/test2")
    public String test2() {
        return "hello = 222" ;
    }


    @GetMapping("/testCookies")
    public String testCookies(HttpServletRequest request) {

        System.out.println("hello -----");

        return "hello = " + env;
    }

    @GetMapping("/redis")
    public String testRedis(@Param("message") String message) {
        System.out.println("message = " + message);
        iRedisService.setValue("username", message);
        return "hello redis ";
    }


    @GetMapping("/getRedis")
    public String testGetRedis() {
        String username = (String) iRedisService.getValue("username");
        return "hello redis " + username;
    }


    @GetMapping("/testFeign")
    public String testFeign() {

        String s = memberClient.orderTest("Xiao11111 ==> ");
        System.out.println(s);
        return "hello";
    }

}
